////////////////////////////////////////////////////////////////////////////////
/// Midnight Circus 2007
////////////////////////////////////////////////////////////////////////////////

namespace GatherTogether
{
    namespace GatherDropRates
    {
        class Node : System.Collections.Generic.IEnumerable<Loot>, System.IComparable<Node>
        {
            protected string m_nodeType;
            protected System.Collections.Hashtable m_loots = new System.Collections.Hashtable();

            public Node(string nodeType)
            {
                m_nodeType = nodeType;
            }

            public string Id
            {
                get
                {
                    return m_nodeType;
                }
            }

            public System.Collections.Generic.IEnumerator<Loot> GetEnumerator()
            {
                foreach (System.Collections.DictionaryEntry entry in m_loots)
                {
                    yield return entry.Value as Loot;
                }
            }

            System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
            {
                return GetEnumerator();
            }

            public bool Equals(Node other)
            {
                return m_nodeType == other.m_nodeType;
            }

            public int CompareTo(Node other)
            {
                return m_nodeType.CompareTo(other.m_nodeType);
            }

            public void AddLoot(GatherDropRates.Loot loot)
            {
                Loot myLoot = m_loots[loot.Id] as Loot;

                // check to see if a loot with this id already exists
                if (myLoot == null)
                {
                    // it does not, so add a new entry to the table
                    m_loots.Add(loot.Id, loot);
                }
                else
                {
                    // it does, so increment the existing table entry
                    myLoot.Count += loot.Count;
                }
            }
        }
    }
}
